﻿using System;
using System.Linq.Expressions;
using Xtensive.Orm;

namespace PartialIndex.Model
{
    /*
     * To define partial index you should provide a method of Expression<Func<T, bool>> type that will be used to 
     * filter entities for inclusion in index.
     * The method can be declared right inside the entity class.
     * However, filters can be extracted to a separate class, see Employee.cs for details
     * 
     * More on partial indexes: http://en.wikipedia.org/wiki/Partial_index
     */
    [HierarchyRoot]
    [Index("TwitterAccount", Filter = "TwitterAccountFilter")]
    public class Person : Entity
    {
        private static Expression<Func<Person, bool>> TwitterAccountFilter()
        {
            return user => user.TwitterAccount != null;
        }

        [Field, Key]
        public int Id { get; private set; }

        [Field(Nullable = true)]
        public string TwitterAccount { get; set; }

        [Field]
        public string FirstName { get; set; }

        [Field]
        public string LastName { get; set; }

        public Person(Session session)
            : base(session)
        {}
    }
}
